import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: true,
		userInfo: {},
		slider: false
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
			console.log(state.userInfo);
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo'
			})
		},
		changeSlider(state, payload) {
			if (typeof(payload) === "boolean") {
				state.slider = Boolean(payload)
				return
			}
			state.slider = !state.slider;
		},
	},
	actions: {

	}
})

export default store
